// index.js
// 获取应用实例
const app = getApp()
var map = require('../../libs/amap-config');
var shanghai=require('data/shanghai')
const setting={
  longitude:121.045332,
  latitude:31.19884,
  scale:8.8,
  rotate:100,
  skew:50
}

const marker1={
  id:1,
  longitude:109.51343536376953,
  latitude:18.944446190333146,
  title:'marker1',
  zIndex:999,
  callout:{
    content:'iam marker1',
    color:'#333333',
    fontSize:12,
    barderRadius:10,
    borderWidth:2,
    boderColor:'#000000',
    bgColor:'#cccccc',
    padding:2,
    textAlign:'center',
    display:'BYCLICK'
  }
}

const marker2={
  id:2,
  longitude:109.3520736694336,
  latitude:18.933242758300203,
  iconPath:'../../static/img/car.png',
  width:20,
  height:20,
  customCallout:{
    display:'ALWAYS',
    anchorX:0,
    anchorY:0
  }
}

const marker3={
  id:3,
  longitude:109.46640014648438,
  latitude:18.98941471523932,
  label:{
    content:'我是label',
    color:'#fff',
    fontSize:12,
    anchorX:0,
    anchorY:0,
    borderWidth:1,
    borderRadius:10,
    padding:3,
    borderColor:'#ffffff',
    bgColor:'#ff6701',
    textAlign:'center'
  }
}

const polyline1=
{
  points:[
    {latitude:19.05465429219405,longitude:109.42863464355469},
    {latitude:18.994933481426877,longitude:109.41936492919922},
    {latitude:18.97350665991898,longitude:109.35104370117188},
    {latitude:18.964415660658197,longitude:109.24701690673828},
    {latitude:18.999802829053262,longitude:109.2319107055664},
  ],
  colorList:["#f05945","#5eaaa8","#a3d2ca"],
  width:2,
  borderColor:"#cccccc"
}

const polygon1=
{
  points: [
    {latitude:19.002724369237626,longitude:109.37885284423827},
    {latitude:19.01716900831182,longitude:109.40631866455078},
    {latitude:18.943472008694652,longitude:109.47463989257812},
    {latitude:18.92626052923276,longitude:109.43927764892578},
    {latitude:18.94850521929427,longitude:109.3864059448242},
    {latitude:19.002724369237626,longitude:109.37885284423827}
  ],
  strokeWidth:3,
  strokeColor:"#ffe9d6",
  fillColor:"#a7d0cd"
}

Page({
  data: {
    setting:setting,
    // markers:[{...marker1},{...marker2},{...marker3}],
    // polyline:[{...polyline1}],
    // polygons:[{...polygon1}]
  },
  onLoad:function(){
    console.log(shanghai);
    this.addPolygon(shanghai)
  },
  addPolygon:function(data){
    let polygon = new map.Polygon({
      path: data,
      fillColor: '#ccebc5',
      strokeOpacity: 1,
      fillOpacity: 0.5,
      strokeColor: '#2b8cbe',
      strokeWeight: 1,
      strokeStyle: 'dashed',
      strokeDasharray: [5, 5],
  });
  polygon.on('mouseover', () => {
      polygon.setOptions({
          fillOpacity: 0.7,
          fillColor: '#7bccc4',
      });
  });
  polygon.on('mouseout', () => {
      polygon.setOptions({
          fillOpacity: 0.5,
          fillColor: '#ccebc5',
      });
  });
  map.add(polygon);
  }
})
